//
//  detailCommond.m
//  HuiPinZhiJia
//
//  Created by MS on 16/8/31.
//  Copyright © 2016年 MS. All rights reserved.
//

#import "detailCommond.h"

@interface detailCommond ()<UITextViewDelegate>

@property (nonatomic,strong)UIScrollView *scroll;
@property (nonatomic,strong)UIView *view1;
@property (nonatomic,strong)UIView *view2;
@property (nonatomic,strong)UIView *view3;
@property (nonatomic,strong)UIView *view4;
@property (nonatomic,strong)UITextField *emilText;
@property (nonatomic,strong)UITextView *commondText;
@property (nonatomic,strong)UITextField *yanZhengText;
@property (nonatomic,strong)UIButton *yanZhengBtn;
@property (nonatomic,strong)UIButton *submitCommond;
@end

@implementation detailCommond

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"商品评论";    
    
//    [self createScroll];//创建滚动视图
//    
//    [self createBtn];//创建查看评论button
//    
//    [self createCommond];//选择评论
//    
//    [self createTextField];//创建输入框
//    UIButton *btn = [self.view viewWithTag:10000];
//    btn.selected = YES;
//    [self.scroll addSubview:self.view1];
    // Do any additional setup after loading the view.
}

- (void)createScroll
{
    _scroll = [[UIScrollView alloc]init];
    _scroll.frame = CGRectMake(0, 0, screenWidth, screenHeight);
    _scroll.contentSize = CGSizeMake(screenWidth, screenHeight*3/2);
    [self.view addSubview:_scroll];
    
//    用户名
    UILabel *label = [[UILabel alloc]init];
    label.text = @"用户名:";
    label.font = [UIFont systemFontOfSize:20];
    label.textColor = [UIColor grayColor];
    label.frame = CGRectMake(10, 360, 80, 50);
    [self.scroll addSubview:label];
    
//    匿名用户
    UILabel *label1 = [[UILabel alloc]init];
    label1.text = @"匿名用户";
    label1.font = [UIFont systemFontOfSize:22];
    label1.frame = CGRectMake(92, 360, 130, 55);
    [self.scroll addSubview:label1];
    
    UIButton *selectBtn = [self.view viewWithTag:10];
    selectBtn.selected = YES;
}

#pragma 创建邮箱与评论内容、验证码 textField
- (void)createTextField
{
    //创建邮箱textFild
    _emilText = [[UITextField alloc]initWithFrame:CGRectMake(10, 460, screenWidth - 20, 40)];
    _emilText.clearButtonMode = UITextFieldViewModeAlways;
    [_emilText.layer setCornerRadius:5];
    _emilText.layer.borderWidth = 1;
    _emilText.layer.borderColor = [UIColor grayColor].CGColor;
    _emilText.placeholder = @"E-mail";
    [self.scroll addSubview:_emilText];
    
//    创建评论内容
    _commondText = [[UITextView alloc]initWithFrame:CGRectMake(10, 525, screenWidth - 20, 150)];
    _commondText.font = [UIFont systemFontOfSize:17];
    _commondText.layer.borderWidth = 1;
    _commondText.layer.borderColor = [UIColor grayColor].CGColor;
    [_commondText.layer setCornerRadius:5];
    _commondText.text = @"评论内容";
    _commondText.delegate = self;//UITextView 通过代理方法 猥琐实现placeholder功能
    _commondText.textColor = [UIColor grayColor];
    [self.scroll addSubview:_commondText];
    
    //验证码
    _yanZhengText = [[UITextField alloc]initWithFrame:CGRectMake(10, 680, screenWidth - 120, 40)];
    _yanZhengText.layer.borderWidth = 1;
    _yanZhengText.layer.borderColor = [UIColor grayColor].CGColor;
    [_yanZhengText.layer setCornerRadius:5];
    _yanZhengText.placeholder = @"验证码";
    _yanZhengText.textColor = [UIColor grayColor];
    [self.scroll addSubview:_yanZhengText];
    
    //验证码Button
    _yanZhengBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _yanZhengBtn.frame = CGRectMake(screenWidth - 100, 680, 80, 40);
    [_yanZhengBtn setTitle:@"验证码" forState:UIControlStateNormal];
    [_yanZhengBtn.layer setCornerRadius:5];
    [_yanZhengBtn addTarget:self action:@selector(yanZhengBtn:) forControlEvents:UIControlEventTouchUpInside];
    [_yanZhengBtn setBackgroundColor:[UIColor redColor]];
    [self.scroll addSubview:_yanZhengBtn];
    
    //提交评论
    _submitCommond = [UIButton buttonWithType:UIButtonTypeCustom];
    _submitCommond.frame = CGRectMake(10, 725, screenWidth - 20, 45);
    [_submitCommond setTitle:@"提交评论" forState:UIControlStateNormal];
    [_submitCommond setBackgroundColor:[UIColor colorWithRed:0.33 green:0.67 blue:0.87 alpha:1.00]];
    [_submitCommond addTarget:self action:@selector(submitBtn:) forControlEvents:UIControlEventTouchUpInside];
    [_submitCommond.layer setCornerRadius:5];
    
    [self.scroll addSubview:_submitCommond];
}
#pragma mark TiJiaoPingLunButton
-(void)submitBtn:(UIButton *)sender
{
    
}

#pragma mark YanZhengButton
- (void)yanZhengBtn:(UIButton *)sender
{

}

#pragma mark UITextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if ([_commondText.text isEqualToString:@"评论内容"])
    {
        _commondText.text = @"";
        _commondText.textColor = [UIColor blackColor];
    }
}
-(void)textViewDidEndEditing:(UITextView*)textView{
    if(textView.text.length<1){
        textView.text=@"评论内容";
        textView.textColor=[UIColor grayColor];
    }
}

//勾选评论
- (void)createCommond
{
    int i;
    NSArray *arr = [NSArray arrayWithObjects:@"非常好|",@"很好|",@"一般|",@"不行|",@"很差",nil];
    for (i = 0;i < 5; i++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(5+ (screenWidth - 5)/5*i,400, (screenWidth - 10)/5, 55);
        [btn setImage:[UIImage imageNamed:@"feixuanzhong"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"xuanzhong.png"] forState:UIControlStateSelected];
//        UIEdgeInsets insets = {top, left, bottom, right};
        [btn setImageEdgeInsets:UIEdgeInsetsMake(btn.frame.size.height*3.5/10, btn.frame.size.width*2/10,btn.frame.size.height*3.5/10,btn.frame.size.width*7/10)];
        btn.tag = 10 + i;
        [self.scroll addSubview:btn];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(22, 8, 60, 40)];
        label.textColor = [UIColor blackColor];
        label.font = [UIFont systemFontOfSize:15];
        label.text = arr[i];
        [btn addTarget:self action:@selector(selectBtn:) forControlEvents:UIControlEventTouchUpInside];
        [btn addSubview:label];
    }
}

//勾选评论点击事件
- (void)selectBtn:(UIButton *)sender
{
    if (sender.tag == 10)
    {
        sender.selected = YES;
        UIButton *btn1 = [self.view viewWithTag:11];
        UIButton *btn2 = [self.view viewWithTag:12];
        UIButton *btn3 = [self.view viewWithTag:13];
        UIButton *btn4 = [self.view viewWithTag:14];
        
        btn1.selected = NO;
        btn2.selected = NO;
        btn3.selected = NO;
        btn4.selected = NO;
    }else if(sender.tag == 11)
    {
        sender.selected = YES;
        UIButton *btn1 = [self.view viewWithTag:10];
        UIButton *btn2 = [self.view viewWithTag:12];
        UIButton *btn3 = [self.view viewWithTag:13];
        UIButton *btn4 = [self.view viewWithTag:14];
        
        btn1.selected = NO;
        btn2.selected = NO;
        btn3.selected = NO;
        btn4.selected = NO;
    }else if(sender.tag == 12)
    {
        sender.selected = YES;
        UIButton *btn1 = [self.view viewWithTag:10];
        UIButton *btn2 = [self.view viewWithTag:11];
        UIButton *btn3 = [self.view viewWithTag:13];
        UIButton *btn4 = [self.view viewWithTag:14];
        
        btn1.selected = NO;
        btn2.selected = NO;
        btn3.selected = NO;
        btn4.selected = NO;
    }else if(sender.tag == 13)
    {
        sender.selected = YES;
        UIButton *btn1 = [self.view viewWithTag:10];
        UIButton *btn2 = [self.view viewWithTag:11];
        UIButton *btn3 = [self.view viewWithTag:12];
        UIButton *btn4 = [self.view viewWithTag:14];
        
        btn1.selected = NO;
        btn2.selected = NO;
        btn3.selected = NO;
        btn4.selected = NO;
    }else if(sender.tag == 14)
    {
        sender.selected = YES;
        UIButton *btn1 = [self.view viewWithTag:10];
        UIButton *btn2 = [self.view viewWithTag:11];
        UIButton *btn3 = [self.view viewWithTag:13];
        UIButton *btn4 = [self.view viewWithTag:12];
        
        btn1.selected = NO;
        btn2.selected = NO;
        btn3.selected = NO;
        btn4.selected = NO;
    }
}

//查看评论
- (void)createBtn
{
    for (int i = 0; i < 4; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake((screenWidth+0.5)/4 * i, 0, screenWidth/4, 60);
        btn.tag = 10000 + i;
        [btn.layer setBorderWidth:1];
        btn.layer.borderColor = [UIColor colorWithRed:0.94 green:0.94 blue:0.94 alpha:1.00].CGColor;
        
        [btn setTitleColor:[UIColor colorWithRed:0.73 green:0.84 blue:0.89 alpha:1.00] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithRed:0.33 green:0.67 blue:0.87 alpha:1.00] forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
        [self.scroll addSubview:btn];
       
        switch (btn.tag)
        {
            case 10000:
                [btn setTitle:@"全部" forState:UIControlStateNormal];
                break;
            case 10001:
                [btn setTitle:@"好评" forState:UIControlStateNormal];
                break;
            case 10002:
                [btn setTitle:@"中评" forState:UIControlStateNormal];
                break;
            case 10003:
                [btn setTitle:@"差评" forState:UIControlStateNormal];
                break;
            default:
                break;
        }
    }
}

#pragma mark 查看评论
- (void)action:(UIButton *)btn
{
    if (btn.tag == 10000)
    {
        [self.scroll addSubview:self.view1];
        UIButton *btn1 = [self.view viewWithTag:10001];
        UIButton *btn2 = [self.view viewWithTag:10002];
        UIButton *btn3 = [self.view viewWithTag:10003];
        btn1.selected = NO;
        btn2.selected = NO;
        btn3.selected = NO;
        btn.selected = YES;
    }else if(btn.tag == 10001)
    {
        [self.scroll addSubview:self.view2];
        UIButton *btn1 = [self.view viewWithTag:10000];
        UIButton *btn2 = [self.view viewWithTag:10002];
        UIButton *btn3 = [self.view viewWithTag:10003];
        btn1.selected = NO;
        btn2.selected = NO;
        btn3.selected = NO;
        btn.selected = YES;
    }else if (btn.tag == 10002)
    {
        [self.scroll addSubview:self.view3];
        UIButton *btn1 = [self.view viewWithTag:10000];
        UIButton *btn2 = [self.view viewWithTag:10003];
        UIButton *btn3 = [self.view viewWithTag:10001];
        btn1.selected = NO;
        btn2.selected = NO;
        btn3.selected = NO;
        btn.selected = YES;
    }else
    {
        [self.scroll addSubview:self.view4];
        UIButton *btn1 = [self.view viewWithTag:10000];
        UIButton *btn2 = [self.view viewWithTag:10002];
        UIButton *btn3 = [self.view viewWithTag:10001];
        btn1.selected = NO;
        btn2.selected = NO;
        btn3.selected = NO;
        btn.selected = YES;
    }
}

- (UIView *)view1
{
    if(!_view1)
    {
        _view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 60, screenWidth, 300)];
        _view1.backgroundColor = [UIColor yellowColor];
    }
    return _view1;
}
- (UIView *)view2
{
    if(!_view2)
    {
        _view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 60, screenWidth, 300)];
        _view2.backgroundColor = [UIColor cyanColor];
    }
    return _view2;
}

- (UIView *)view3
{
    if(!_view3)
    {
        _view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 60, screenWidth, 300)];
        _view3.backgroundColor = [UIColor blackColor];
    }
    return _view3;
}

- (UIView *)view4
{
    if(!_view4)
    {
        _view4 = [[UIView alloc]initWithFrame:CGRectMake(0, 60, screenWidth, 300)];
        _view4.backgroundColor = [UIColor cyanColor];
    }
    return _view4;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
